package net.caixiaomi.info.adapter;

import android.widget.LinearLayout;
import android.widget.TextView;

import net.caixiaomi.info.R;
import net.caixiaomi.info.base.quickadapter.BaseMultiItemQuickAdapter;
import net.caixiaomi.info.base.quickadapter.BaseViewHolder;
import net.caixiaomi.info.base.quickadapter.entity.MultiItemEntity;
import net.caixiaomi.info.model.DltPrizeEntity;
import net.caixiaomi.info.model.MatchingItem;
import net.caixiaomi.info.util.Constants;

import java.util.List;

/**
 * Created by mac on 2018/9/6.
 */

public class OpenPrizeNumAdapter extends BaseMultiItemQuickAdapter<MultiItemEntity, BaseViewHolder> {
    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public OpenPrizeNumAdapter(List<MultiItemEntity> data) {
        super(data);
        addItemType(Constants.ITEM_MATCH_LIVE0, R.layout.prize_num_norlam_item_layout);
        addItemType(Constants.ITEM_MATCH_LIVE1, R.layout.prize_num_item_layout);
    }

    @Override
    protected void convert(BaseViewHolder helper, MultiItemEntity item) {
        try {
            switch (helper.getItemViewType()){
                case Constants.ITEM_MATCH_LIVE0:
                    bindView(helper,item);
                    break;
                case Constants.ITEM_MATCH_LIVE1:
                    bindFirstView(helper,item);
                    break;
            }
        }catch (Exception e){

        }
    }

    private void bindFirstView(BaseViewHolder helper, MultiItemEntity item){
        DltPrizeEntity entity= (DltPrizeEntity) item;
        helper.setText(R.id.prize_period,entity.getPeriod());
        helper.setText(R.id.prize_date,entity.getPrizeDate());
        LinearLayout ballGroup=helper.getView(R.id.ball_group);
        for(int i=0;i<5;i++){
            LinearLayout ll= (LinearLayout) ballGroup.getChildAt(i);
            TextView tv= (TextView) ll.getChildAt(0);
            tv.setText(entity.getRedPrizeNumList().get(i));
            tv.setBackgroundResource(R.drawable.red_ball);
        }
        for(int i=5;i<7;i++){
            LinearLayout ll= (LinearLayout) ballGroup.getChildAt(i);
            TextView tv= (TextView) ll.getChildAt(0);
            tv.setText(entity.getBluePrizeNumList().get(i-5));
            tv.setBackgroundResource(R.drawable.blue_ball);
        }
    }

    private void bindView(BaseViewHolder helper, MultiItemEntity item){
        DltPrizeEntity entity= (DltPrizeEntity) item;
        helper.setText(R.id.prize_period,entity.getPeriod());
        helper.setText(R.id.prize_date,entity.getPrizeDate());
        LinearLayout ballGroup=helper.getView(R.id.ball_group);
        for(int i=0;i<5;i++){
            LinearLayout ll= (LinearLayout) ballGroup.getChildAt(i);
            TextView tv= (TextView) ll.getChildAt(0);
            tv.setText(entity.getRedPrizeNumList().get(i));
            tv.setBackgroundResource(R.drawable.red_circle);
        }
        for(int i=5;i<7;i++){
            LinearLayout ll= (LinearLayout) ballGroup.getChildAt(i);
            TextView tv= (TextView) ll.getChildAt(0);
            tv.setText(entity.getBluePrizeNumList().get(i-5));
            tv.setBackgroundResource(R.drawable.blue_circle);
        }
    }
}
